package GUI;

/**
 * open new class screen for the administration user type
 */

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class OpenNewClass extends JPanel {
	private JLabel lblOpenNewClass = null;
	private JLabel lblEnterGrade = null;
	private JComboBox cBEnterGrade = null;
	private JButton btnCreate = null;
	private AdminMainMenu adminFrame = null;
	private ConfigureClass confClassScreen = null;
	private Dimension defaultDim = null;
	public Login myLoginFrame=null;
	public AdminMainMenu amn = null;
	public  UserAdmin user = null;
	private String selClass = null;
	
	
	
	private JComboBox getcBEnterGrade()
	{
		
		String[] grades={"1","2","3","4","5","6","7","8","9","10","11","12"};
		
		if(cBEnterGrade==null)
		{
			cBEnterGrade = new JComboBox(grades);
			cBEnterGrade.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					//TODO add class to the DB and add a sequetial number 
					
					selClass = cBEnterGrade.getSelectedItem().toString();
					System.out.println(selClass);
					
				}
			});
			cBEnterGrade.setBounds(187, 67, 133, 20);
		}
		
		return cBEnterGrade;
	}
	
	private JButton getBtnCreate(final AdminMainMenu amn)
	{
		if(btnCreate==null)
		{
			btnCreate = new JButton("Create");
			btnCreate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					//TODO add class to the DB and add a sequetial number 
					//amn.user.SetClass(selClass);
					amn.user.Executed=false;
					amn.user.SetClass(selClass);
					amn.myLoginFrame.client.handleMessageFromClientUI("CreateNewClass "+selClass);
					while(!amn.user.Executed);
					
					
				}
			});
			btnCreate.setBounds(453, 258, 89, 23);
		}
		
		return btnCreate;
		
	}
	
	private void initialize(AdminMainMenu adminFrame)
	{
		
		setLayout(null);
		lblOpenNewClass = new JLabel("Open new class");
		lblOpenNewClass.setBounds(171, 11, 107, 14);
		add(lblOpenNewClass);
			
		lblEnterGrade = new JLabel("Select grade:");
		lblEnterGrade.setBounds(66, 70, 64, 14);
		add(lblEnterGrade);
		add(getcBEnterGrade());
		add(getBtnCreate(adminFrame));
		
	}
	
	
	public void setFrame(AdminMainMenu amm)
	{
		this.adminFrame=amm;
	}
	
	public ConfigureClass getConfigureClassScreen()
	{
		if(confClassScreen==null)
		{
			confClassScreen = new ConfigureClass(adminFrame);
			
			confClassScreen.setSize(getMaximumSize());
		}
		
		return confClassScreen;
	}
	
	
	
	public OpenNewClass(AdminMainMenu adminFrame) {
		super();
		initialize(adminFrame);
		
		
	}
}
